#ifndef _USER_INTERFACE_H_
#define _USER_INTERFACE_H_

#include "CGlobals.h"
#include "CCinematicEditor.h"
#include "CinematicAdjust.h"
#include "SColor.h"
#include <vector>

class IFpsParticleAffector;
class CProperty;

namespace irr
{
	namespace gui
	{
		class IGUIWindow;
		class IGUIListBox;
		class IGUIEditBox;
		class IGUITreeCtrl;
		class IGUIButton;
		class IGUITabControl;
		class IGUICinematicCtrl;
		
	}
}

extern CGlobals* g;

enum E_MENUITEM_TYPE 
{
  MAIN_SCENE_NEW_ITEM,
  MAIN_SCENE_OPEN_ITEM,
  MAIN_SCENE_SAVE_ITEM,
  MAIN_SCENE_SAVE_AS_ITEM,
  MAIN_SCENE_SAVE_CINEMATICS,
  MAIN_SCENE_SET_STR_FILE_ITEM,
  MAIN_SCENE_SET_MUSIC_FILE_ITEM,
  MAIN_SCENE_PFEXPORT_ITEM,
  MAIN_SCENE_QUIT_ITEM,
  MAIN_SCENE_RECENT_FILE_ITEM,
  MAIN_SCENE_RECENT_FILE_SUB_ITEM,  
  MAIN_VIEW_TOOLS_ITEM,
  MAIN_VIEW_PROPERTIES_ITEM,
  MAIN_VIEW_SCENEGRAPH_ITEM,
  MAIN_VIEW_HISTORY_ITEM,
  MAIN_VIEW_LEVEL_PROPERTIES,
  MAIN_VIEW_MAYA_ITEM,
  MAIN_VIEW_FPS_ITEM,
  MAIN_VIEW_WAYPOINT_CAMERA_ITEM,
  MAIN_VIEW_CAMERA_XZ_ITEM,
  MAIN_VIEW_CAMERA_XY_ITEM,
  MAIN_VIEW_CAMERA_YZ_ITEM,
  MAIN_VIEW_SWITCH_GRID_ITEM,
  MAIN_EDIT_UNDO_ITEM,
  MAIN_EDIT_REDO_ITEM,
  MAIN_EDIT_CLONE_ITEM,
  MAIN_EDIT_CLEAR_HISTORY_ITEM,
  MAIN_TOOLS_BUILD_ITEM,
  MAIN_TOOLS_LAUNCH_ITEM,
  MAIN_TOOLS_CLEAN_ITEM,
  
  MAIN_TOOLS_SH_COLLISION,
  MAIN_TOOLS_SH_NAVMESH,
  MAIN_TOOLS_SH_SKYBOX,
  MAIN_TOOLS_SH_CAMERAAREA,
  MAIN_TOOLS_SH_TRIGGER,

  MAIN_HELP_CONTROLS_ITEM,
  MAIN_HELP_ABOUT_ITEM,
  NUM_MENUITEM_TYPES     
};

enum E_WINDOW_IDS
{	
	WND_ID_TOOLS = 1000,
	TOOLS_TABS,
	TOOLS_PS_TABS,
	TOOLS_ID_SERACHBOX,
	TOOLS_ID_PICKLIST,
	TOOLS_ID_TEMPLATE_LIST,
	TOOLS_ID_INSERT_GAME_OBJECT,
	TOOLS_ID_INSERT_GAME_TEMPLATE,
	//TOOLS_ID_INSERT_CUBE_BTN,
	//TOOLS_ID_INSERT_SPHERE_BTN,
	//TOOLS_ID_INSERT_TERRAIN_BTN,
	//TOOLS_ID_INSERT_NAVMESH_BTN,
	TOOLS_ID_INSERT_SKYBOX_BTN,
	//TOOLS_ID_INSERT_CAMERA_BTN,
	//TOOLS_ID_INSERT_BILLBOARD_BTN,
	//TOOLS_ID_INSERT_STATIC_MESH_BTN,
	//TOOLS_ID_INSERT_ANIM_MESH_BTN,
	//TOOLS_ID_INSERT_GEOMETRY_BTN,
	//TOOLS_ID_INSERT_COLLISIONS_BTN,
	TOOLS_ID_MOVE_BTN,
	TOOLS_ID_MOVE_LOCAL_BTN,
	TOOLS_ID_ROTATE_BTN,
	TOOLS_ID_ROTATE_LOCAL_BTN,
	TOOLS_ID_SCALE_BTN,
	TOOLS_ID_DELETE_BTN,
	TOOLS_ID_SNAP2COL_BTN,
	TOOLS_ID_MODIFY_TRIG_BTN,
	TOOLS_ID_CORRECT_CAMAREA_BTN,
	TOOLS_ID_SET_CAMAREA_BTN,
	TOOLS_ID_COPY_CAMERA_BTN,
	TOOLS_ID_UNIMPLEMENTED_BTN,
	TOOLS_ID_SAVE_EFFECTS_BTN,
	TOOLS_ID_EFFECTS_LIST,
	TOOLS_ID_PS_LIST,
	TOOLS_ID_ADD_EFFECT_BTN,
	TOOLS_ID_REMOVE_EFFECT_BTN,
	TOOLS_ID_CLONE_EFFECT_BTN,
	TOOLS_ID_RESTART_EFFECT_BTN,
	TOOLS_ID_ADD_PS_BTN,
	TOOLS_ID_REMOVE_PS_BTN,
	TOOLS_ID_CLONE_PS_BTN,
	TOOLS_ID_COPY_PS_BTN,
	TOOLS_ID_PASTE_PS_BTN,
	TOOLS_ID_AFFECTORS_LIST,
	TOOLS_ID_AFFECTORS_COMBO,
	TOOLS_ID_ADD_AFFECTOR_BTN,
	TOOLS_ID_REMOVE_AFFECTOR_BTN,
	TOOLS_ID_TEMPLATES_NEW_COMBO,
	TOOLS_ID_ADD_TEMPLATE_BTN,
	TOOLS_ID_DELETE_TEMPLATE_BTN,
	TOOLS_ID_SAVE_TEMPLATE_BTN,
	//TOOLS_ID_AFFECTOR_ATTRACT_POINT,
	//TOOLS_ID_AFFECTOR_ATTRACT_CHECKBOX,
	//TOOLS_ID_AFFECTOR_ATTRACT_AFFECT_X,
	//TOOLS_ID_AFFECTOR_ATTRACT_AFFECT_Y,
	//TOOLS_ID_AFFECTOR_ATTRACT_AFFECT_Z,
	//TOOLS_ID_AFFECTOR_FADEOUT_TIME,
	//TOOLS_ID_AFFECTOR_FADEOUT_COLOR,
	//TOOLS_ID_AFFECTOR_GRAVITY,
	//TOOLS_ID_AFFECTOR_GRAVITY_TIME,
	//TOOLS_ID_AFFECTOR_ROTATION_POINT,
	//TOOLS_ID_AFFECTOR_ROTATION_SPEED,
	//TOOLS_ID_AFFECTOR_SIZE_FADE_TIME,
	//TOOLS_ID_AFFECTOR_SIZE_GROW_TIME,
	//TOOLS_ID_AFFECTOR_SIZE_TARGET,
	//TOOLS_ID_AFFECTOR_SIZE_VARIATION,
	//TOOLS_ID_AFFECTOR_SPIN_TIME,
	//TOOLS_ID_AFFECTOR_SPIN_VARIATION,
	TOOLS_ID_PS_TEXTURE,

	WND_ID_PROPERTIES = 1100,
	PROP_FILE_BTN,
	PROP_EDIT_CINEMATIC_BTN,
	PROP_EDIT_OFFSET_BTN, //for camera control point
	PROP_SNAP_TARGET_TO_EDGE_BTN, //for camera control point
	PROP_EDIT_MOVE_TO_CAM, //for spiderman
	PROP_TABS,
	PROP_LINK_BTN,
	PROP_APPLY_FOG_BTN,
	PROP_RESTART_EFFECT_BTN,
	PROP_PLAY_BTN,
	PROP_LOOP_CHECK,	
	PROP_EDIT_CINEMATIC_WO,
	PROP_EDIT_CINEMATIC_WI,
	PROP_EDIT_CINEMATIC_IO,
	PROP_EDIT_CINEMATIC_OI,
	PROP_EDIT_CINEMATIC_SP, 
	PROP_EDIT_CINEMATIC_DE,
	PROP_EDIT_CINEMATIC_IT,

	WND_ID_SCENEGRAPH = 1200,
	SCENEGRAPH_ID_TREEVIEW,
	SCENEGRAPH_ID_CONTEXTMENU,
	SCENEGRAPH_ID_SEARCHBOX,
	SCENEGRAPH_ID_UP,
	SCENEGRAPH_ID_DOWN,
	SCENEGRAPH_ID_TOP,
	SCENEGRAPH_TABS,
	CONTEXTMENU_ID_DELETE,
	CONTEXTMENU_ID_CLONE,
	CONTEXTMENU_ID_MOVE_TO_ROOT,
	CONTEXTMENU_ID_UP,
	CONTEXTMENU_ID_DOWN,
	CONTEXTMENU_ID_NEW_GROUP,
	CONTEXTMENU_ID_ACTIVATE_CAMERA,
	CONTEXTMENU_ID_EDIT_CINEMATIC,
	CONTEXTMENU_ID_ADJUST_CINEMATIC,
	CONTEXTMENU_ID_SELECT,
	CONTEXTMENU_ID_LINK_TO,
	SCENEGRAPH_VISIBLE_ID_LIST,
	SCENEGRAPH_INVISIBLE_ID_LIST,
	SCENEGRAPH_LOCKED_ID_LIST,
	CONTEXTMENU_ID_VISIBLE,
	CONTEXTMENU_ID_INVISIBLE,
	CONTEXTMENU_ID_LOCK,
	CONTEXTMENU_ID_UNLOCK,	
	CONTEXTMENU_ID_UNLOCK_VISIBLE_LIST,
	VISBLE_LIST_ID_SORT_BTN,
	VISBLE_LIST_ID_FILTER_BTN,

	WND_ID_HISTORY = 1300,
	HISTORY_ID_LIST,

	WND_ID_CINEMATIC = 1400,
	CINEMATIC_ID_KEY_FRAME_LIST,
	CINEMATIC_ID_UP_BTN,
	CINEMATIC_ID_DOWN_BTN,
	CINEMATIC_ID_DELETE_BTN,
	CINEMATIC_ID_CLONE_BTN,
	CINEMATIC_ID_COMMAND_COMBO,
	CINEMATIC_ID_OBJECT_COMBO,
	CINEMATIC_ID_ADD_BTN,
	CINEMATIC_ID_FOCUS_BTN,
	CINEMATIC_ID_PLAY_BTN,
	CINEMATIC_ID_LINK_BTN,	
	CINEMATIC_ID_CHANGE_BTN,
	CINEMATIC_ID_PREVIEW_BTN,
	CINEMATIC_ID_VIEW_BTN,

	CINEMATIC_ID_MOVE_RANGE_BTN,
	CINEMATIC_ID_SAVE_FILE,
	CINEMATIC_ID_FIRST_KF,
	CINEMATIC_ID_PREVIOUS_KF,
	CINEMATIC_ID_NEXT_KF,
	CINEMATIC_ID_LAST_KF,
	CINEMATIC_ID_FILE_BROWSE_BUTTON,
	MSG_BOX_CONFIRM_MOVE_RANGE,


	WND_ID_CINEMATIC_NAME = 1500,
	CINEMATIC_NAME_ID_EDIT_NAME_BOX,

	WND_ID_EFFECT_NAME = 1600,
	EFFECT_NAME_ID_EDIT_NAME_BOX,
	EFFECT_NAME_ID_OK_BTN,
	EFFECT_NAME_ID_OK_BTN_CLONE,

	WND_ID_PS_NAME = 1700,
	PS_NAME_ID_EDIT_NAME_BOX,
	PS_NAME_ID_OK_BTN,

	WND_ID_TEMPLATE_NAME = 1800,
	TEMPLATE_NAME_ID_EDIT_NAME_BOX,
	TEMPLATE_NAME_ID_OK_BTN,

	MSG_BOX_SAVE_SCENE,
	MSG_BOX_AUTOSAVE_SCENE,
	MSG_BOX_SAVE_CINEMATIC,

	MSG_BOX_CONFIRM_DELETE,

	MSG_BOX_CONFIRM_COPY_CAMERA,
	
	WND_ID_CINEMATIC_CTRL = 2000,
	CINEMATIC_ID_CINEMATIC_CTRL,
	CINEMATIC_CONTEXT_MENU,
	CINEMATIC_CONTEXT_NEW_OBJ_THREAD,
	CINEMATIC_CONTEXT_NEW_BASIC_THREAD,
	CINEMATIC_CONTEXT_NEW_CAMERA_THREAD,
	CINEMATIC_CONTEXT_NEW_PLAYER_THREAD,
	CINEMATIC_CONTEXT_EDIT_THREAD,
	CINEMATIC_CONTEXT_RENAME_THREAD,
	CINEMATIC_CONTEXT_DELETE_THREAD,
	CINEMATIC_CONTEXT_CLONE_THREAD,
	CINEMATIC_CONTEXT_COPY_THREAD,
	CINEMATIC_CONTEXT_PASTE_THREAD,
	CINEMATIC_CONTEXT_COPY_CINEMATIC,
	CINEMATIC_CONTEXT_CUT_CINEMATIC,
	CINEMATIC_CONTEXT_PASTE_CINEMATIC,
	CINEMATIC_CONTEXT_COPY_GROUP_CINEMATIC,
	CINEMATIC_CONTEXT_PASTE_GROUP_CINEMATIC,
	

	WND_ID_LEVEL_PROPERTIES = 3000,	
	WND_ID_OPEN_MUSIC_FILE,
	WND_ID_OPEN_TEXT_FILE,
	WND_ID_OPEN_LOADING_FILE,


	WND_ID_RENAME_THREAD,
	WND_ID_EDIT_RENAME_THREAD,

	WND_ID_CINEMATIC_ADJUST = 3100,
	CINEMATIC_ADJUST_ID_OK_BTN,
	CINEMATIC_ADJUST_ID_CANCEL_BTN,

	WND_ID_PFEXPORTER_WIN = 4000,
	PFEXPORT_EDIT_TILE_SIZE,
	PFEXPORT_EDIT_TILE_SIZE_Z,
	PFEXPORT_EDIT_MIN_VALUE,
	PFEXPORT_EDIT_MAX_VALUE,
	PFEXPORT_EDIT_OFFSET_VALUE,
	PFEXPORT_EDIT_SR,
	PFEXPORT_EDIT_SG,
	PFEXPORT_EDIT_SB,
	PFEXPORT_BT_EXPORT,
	PFEXPORT_BT_CHECK_ALL,
	PFEXPORT_CHECKBOX_0,		
	PFEXPORT_CHECKBOX_RESERVED = 4999,
};

enum E_DIALOG_IDS
{
	FILE_OPEN_STATIC_MESH_DIALOG = 10000,
	//FILE_OPEN_TERRAIN_DIALOG,
	//FILE_OPEN_NAVMESH_DIALOG,
	FILE_OPEN_SKYBOX_DIALOG,
	FILE_OPEN_CAMERA_DIALOG,
	//FILE_OPEN_ANIMATED_MESH_DIALOG,
	FILE_OPEN_SCENE_DIALOG,
	FILE_SAVE_SCENE_DIALOG,
	FILE_PROP_FILE_OPEN_DIALOG,
	FILE_SET_STRINGS_FILE_DIALOG,
	FILE_SET_MUSIC_FILE_DIALOG,
	//FILE_OPEN_GEOMETRY_DIALOG,
	//FILE_OPEN_COLLISIONS_DIALOG,
};

enum E_UI_EDIT_TYPE
{
	UI_EDIT_ACTION_NONE = 0,
	UI_EDIT_ACTION_MOVE,
	UI_EDIT_ACTION_MOVE_LOCAL,
	UI_EDIT_ACTION_ROTATE,
	UI_EDIT_ACTION_ROTATE_LOCAL,
	UI_EDIT_ACTION_SCALE,
	UI_EDIT_ACTION_MODIFY
};

enum E_UI_PROP_TYPE
{
	//standard types
	UI_PROP_TYPE_INT,
	UI_PROP_TYPE_FLOAT,
	UI_PROP_TYPE_VECTOR,
	UI_PROP_TYPE_COLOR,
	UI_PROP_TYPE_STRING,	
	UI_PROP_TYPE_LIST,
};

class CUserInterface
{
public:
	CUserInterface();
	~CUserInterface();
public:
	IGUIWindow* m_ToolsWindow;
	IGUIWindow* m_PropertiesWindow;
	IGUIWindow* m_SceneGraphWindow;
	IGUIWindow* m_HistoryWindow;
	IGUIWindow* m_SceneGraphPropertiesWindow;
	IGUIWindow* m_LevelProperties;
	IGUIWindow* m_PFExporterWindow;

	IGUIWindow* m_CinematicWindow;
	IGUICinematicCtrl* m_cinematicCtrl;

	IGUIEditBox* m_searchBoxForObjectList;

	irr::core::stringw m_oldSearchBoxText;

	IGUIListBox* m_GameObjectList;

	IGUITreeCtrl* m_sceneGraphTree;
	IGUIListBox* m_HistoryList;
	IGUIListBox* m_SceneGraphPropertiesVisibleList;
	IGUIListBox* m_SceneGraphPropertiesInvisibleList;
	IGUIListBox* m_SceneGraphPropertiesLockedList;
	IGUIEditBox* m_searchBox;
	IGUIButton* m_FilterPushButton;

	IGUIButton* m_MovePushButton;
	IGUIButton* m_MoveLocalPushButton;
	IGUIButton* m_RotatePushButton;
	IGUIButton* m_RotateLocalPushButton;
	IGUIButton* m_ScalePushButton;
	IGUIButton* m_ModifyPushButton;
	IGUIButton* m_CorrectCamAreaButton;
	IGUIButton* m_SetCameraButton;
	IGUIButton* m_CopyCameraButton;

	CCinematicEditor m_CinematicEditor;
	CCinematicAdjust m_CinematicAdjust;

	void * m_Clipboard;

public:

	int init();
	void update();
	bool receiveEvent(const SEvent& event);
	void populateGameObjectList();
	void populateEffectsList();
	void populateTemplatesCombo();
	void populateTemplatesList();
	int getEditAction();
	void createSelectedObjectProperties();
	void createSelectedTemplateProperties();
	void createSelectedPSProperties();
	IFpsParticleAffector* getSelectedAffector();
	void createSelectedAffectorProperties();
	void createFPExporterWindow();
	void FPExportWinButtonPressed(const SEvent& event);
	void FPExportWinCheckBoxChanged(const SEvent& event);

	void createLevelProprtiesWindow();
	void clearPropertiesWindow();
	void updateProperties();
	void updateProperties(IAttributes* pAttr, array<CProperty>* pProperties);
	void updateWindowsPosition();
	void showSaveWarning();
	void showAutosaveWarning();	
	void trySave();

	void setSceneNodeVisible(int ID,bool bVisible);
	void removeSceneNodeFromList(int ID,bool bVisible);	
	void setSceneNodeLocked(int ID,bool bLocked);
	IGUIListBox* addCListBox(IGUIEnvironment* enviroment, const core::rect<s32>& rectangle,
		IGUIElement* parent=0, s32 id=-1, bool drawBackground=false);
	void unselectButtons();

	bool IsEffectsTabSelected();

	void HideRestoreWindows(bool hide);

private:
	bool m_bTerrainLoaded;

	IGUIEditBox* m_effectNameBox;
	int m_copyedEffectIndex;
	int m_copyedPsIndex;

	IGUITabControl* m_PSTabs;
	IGUITab* m_PSAttrTab;
	IGUITab* m_PSEmitterTab;
	IGUITab* m_PSAffectorTab;
	IGUITab* m_PSMatTab;

	IGUITabControl* m_ToolsTabs;
	IGUITab* m_ToolsObjectsTab;
	IGUITab* m_ToolsTemplatesTab;
	IGUITab* m_ToolsEffectsTab;

	IGUITabControl* m_PropertiesTabs;
	IGUITab* m_PropertiesStandardTab;
	IGUITab* m_PropertiesCustomTab;

	IGUITabControl* m_SceneGraphTabs;
	IGUITab* m_SceneGraphTreeTab;
	IGUITab* m_SceneGraphPropertiesVisibleTab;
	IGUITab* m_SceneGraphPropertiesInvisibleTab;
	IGUITab* m_SceneGraphPropertiesLockedTab;
	

	CProperty* m_FileOpenProp;	
	stringc m_UserBrowsePath;
	stringc m_SkyBoxTextures[6];
	int m_SkyBoxTextureIndex;
	array<CProperty> m_Properties;
	array<CProperty> m_PSProperties;
	array<CProperty> m_AffectorProperties;
	array<CProperty> m_MatProperties;
	array<CProperty> m_TemplateProperties;
	dimension2d<u32> m_LastScreenSize;

	void createMainMenu();
	void createToolsWindow();
	void createPropertiesWindow();
	void createSceneGraphWindow();
	void createHistoryWindow ();

	void showAboutBox();
	void showControlsHelpBox();
	int createProperty(CSceneObject* sceneObject, stringw name, int type, s32 x, s32 y, bool bUserData, IGUIElement* parent);
	int createProperty(stringw name, int type, s32 x, s32 y, IGUIElement* parent, array<CProperty>* pProperties);
	bool m_bQuitAfterSave;

	bool m_bUseEditorRelativePath;	
public:
	int stringToInt(stringw str);
	f32 stringToFloat(stringw str);
	stringw vector3DToString(const vector3df* vector, u16 precision);
	vector3df stringToVector3D(stringw str);
	stringw colorToString(const SColor* color);
	SColor stringToColor(stringw str);

	CProperty* m_linkChangedProp;

	stringc m_sceneName;

	std::vector<bool> m_windowVisibles;

private:	
	bool propertyEditBoxEnter(const SEvent& event);
	bool propertyButtonPressed(const SEvent& event);
	bool propertyComboBoxChanged(const SEvent& event);
	bool propertyCheckBoxChanged(const SEvent& event);

private:
	int loadRecentFiles();
	int saveRecentFiles();

private:
	irr::core::array<irr::core::stringw> m_recentFiles;

	irr::core::stringc m_startupDir;

	irr::core::array<irr::core::stringw> m_allGameObject;

friend class CCinematicEditor;
};

#endif